﻿/* Author:
 *  Andrea Vandin
 */
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace TripLOAMobile.InternalEntities
{
    /// <summary>
    /// This class represents an address.
    /// Provides the property for each component of the address, and a method to obtain a readeble format
    /// </summary>
    public class AddressFields
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="AddressFields"/> class.
        /// </summary>
        public AddressFields()
        {
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="AddressFields"/> class.
        /// </summary>
        /// <param name="street">The street.</param>
        /// <param name="city">The city.</param>
        /// <param name="province">The province.</param>
        /// <param name="zipCode">The zip code.</param>
        /// <param name="state">The state.</param>
        public AddressFields(string street, string city, string province, string zipCode, string state)
        {
            Street = street;
            City = city;
            Province = province;
            State = state;
            ZipCode = zipCode;
        }

        /// <summary>
        /// Gets or sets the street component of the address.
        /// </summary>
        /// <value>The street.</value>
        public string Street
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the city component of the address.
        /// </summary>
        /// <value>The city.</value>
        public string City
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the province component of the address.
        /// </summary>
        /// <value>The province.</value>
        public string Province
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the zip code component of the address.
        /// </summary>
        /// <value>The zip code.</value>
        public string ZipCode
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the state component of the address.
        /// </summary>
        /// <value>The state.</value>
        public string State
        {
            get;
            set;
        }

        //"street","zipCode" "city" "province","state"

        /// <summary>
        /// This methods returns a string representation of the address contained in the object.
        /// The address will be in the form [street,][zipcode][ city] [ province][,state]
        /// </summary>
        /// <returns>The string representation of the address</returns>
        public string getReadableString()
        {
            StringBuilder sb = new StringBuilder("");
            bool commaInserted = false;
            if ((Street != null) && (Street != ""))
                sb.Append(Street);
            if ((ZipCode != null) && (ZipCode != ""))
            {
                sb.Append("," + ZipCode);
                commaInserted = true;
            }
            if ((City != null) && (City != ""))
            {
                if (commaInserted)
                    sb.Append(" " + City);
                else
                {
                    sb.Append("," + City);
                    commaInserted = true;
                }
            }
            if ((Province != null) && (Province != ""))
            {
                if (commaInserted)
                    sb.Append(" " + Province);
                else
                {
                    sb.Append("," + Province);
                    commaInserted = true;
                }
            }
            if ((State != null) && (State != ""))
                sb.Append("," + State);

            string ret = sb.ToString().Trim();
            if(ret.StartsWith(","))
                ret=ret.Substring(1);
            if(ret.EndsWith(","))
                ret=ret.Substring(0,ret.Length-1);

            return ret;
        }

    }
}
